package edu.suda.xsap.service.impl;

import edu.suda.xsap.dto.CourseDto;
import edu.suda.xsap.dto.convert.CourseConvert;
import edu.suda.xsap.entity.Course;
import edu.suda.xsap.mapper.CourseMapper;
import edu.suda.xsap.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseConvert courseConvert;

    @Autowired
    private CourseMapper courseMapper;
    @Override
    public void save(Course course) {courseMapper.save(course);
    }

    @Override
    public void delete(Integer id) {
        courseMapper.delete(id);
    }

    @Override
    public void update(Course course) {
        courseMapper.update(course);
    }

    @Override
    public CourseDto findById(Integer id) {
        Course course = courseMapper.findById(id);
        return courseConvert.toDto(course);
    }

    @Override
    public CourseDto findByName(String name) {
        Course course = courseMapper.findByName(name);
        return courseConvert.toDto(course);
    }

    @Override
    public List<CourseDto> findAll() {
        List<Course> courses = courseMapper.findAll();
        return courseConvert.toDtoList(courses);

    }
}
